package com.shiroha.video.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.shiroha.common.feign.client.NotificationClient;
import com.shiroha.video.mapper.LikeMapper;
import com.shiroha.video.pojo.Like;
import com.shiroha.video.service.ILikeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.UUID;

import static com.shiroha.video.pojo.table.Tables.LIKE;


@Service
@AllArgsConstructor
public class LikeServiceImpl extends ServiceImpl<LikeMapper, Like> implements ILikeService {

    private final NotificationClient notificationClient;

    /**
     * 点赞作品或评论
     *
     * @param userId    请求者ID
     * @param workId    作品ID
     * @param commentId 评论ID
     * @return 点赞是否成功
     */
    @Override
    public boolean addLike(UUID userId, Long workId, Long commentId) {
        Like like = new Like();
        like.setWorkId(workId);
        like.setCommentId(commentId);
        like.setUserId(userId);
        return this.save(like);
    }

    /**
     * 取消点赞
     *
     * @param userId    请求者ID
     * @param workId    作品ID
     * @param commentId 评论ID
     * @return 取消点赞是否成功
     */
    @Override
    public boolean removeLike(UUID userId, Long workId, Long commentId) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .where(LIKE.USER_ID.eq(userId))
                .and(LIKE.WORK_ID.eq(workId))
                .and(LIKE.COMMENT_ID.eq(commentId));
        return this.remove(queryWrapper);
    }
}
